<template> 
	<div class="JNPF-common-layout">
		<div class="JNPF-common-layout-center">
			<el-row class="JNPF-common-search-box" :gutter="18">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="项目名称">
							<el-select v-model="query.fullName" placeholder="项目名称" clearable >
								<el-option v-for="(item, index) in proNameOptions" :key="index" :label="item.F_FullName" :value="item.F_Id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="签约时间">
                            <el-date-picker v-model="query.signingTime" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
                    </el-col>
                    <el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
					</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="JNPF-common-layout-main JNPF-flex-main">
                    <div class="JNPF-common-head">
					<div>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list" :row-class-name="tableRowClassName">  
					 <el-table-column prop="proName" label="项目名称"  show-overflow-tooltip >
                     <template slot-scope="scope">
                         <p>{{ scope.row.proName }}</p>
                      </template>
                    </el-table-column>
                    <el-table-column label="签订时间"  prop="signingTime" align="center" width="160">
						<template slot-scope="scope">
                            <p class="text-primary">{{scope.row.signingTime | toDate("yyyy-MM-dd") }}</p>
                        </template>
					</el-table-column>
                    <el-table-column label="项目金额(元)"  prop="amount" align="center" width="140">
						<template slot-scope="scope">
						 <p><el-tag type="info">{{ scope.row.amount | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="报销总额(元)"  prop="finAmount" align="center" width="100">
						<template slot-scope="scope">
						 <p><el-tag type="warning">{{ scope.row.finAmount | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="成本总额(元)"  prop="costAmount" align="center" width="120">
						<template slot-scope="scope">
						 <p><el-tag type="warning">{{ scope.row.costAmount | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="项目毛利(元)"  prop="profit" align="center" width="140">
						<template slot-scope="scope">
						 <p><el-tag type="success">{{ scope.row.profit | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="销售提成(元)"  prop="profit" align="center" width="120">
						<template slot-scope="scope">
						 <p><el-tag type="success">{{ scope.row.profit*0.25 | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="实施提成(元)"  prop="profit" align="center" width="120">
						<template slot-scope="scope">
						 <p><el-tag type="success">{{ scope.row.profit*0.25 | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="公司留存(元)"  prop="profit" align="center" width="140">
						<template slot-scope="scope">
						 <p><el-tag type="danger">{{ scope.row.profit*0.5 | currency('¥') }}</el-tag></p>
                     </template>
                     </el-table-column>
                     <el-table-column label="提成分配"  prop="lastTrackState" align="center" width="90">
						<template slot-scope="scope">
                          <span v-if="scope.row.lastTrackState ==1&&scope.row.profit>=10000"><el-tag effect="dark" type="success">已分配</el-tag></span>
                          <span v-else-if="scope.row.lastTrackState ==0&&scope.row.profit>=10000"><el-tag effect="dark" type="warning">未分配</el-tag></span>
                          <span v-else></span>
                       </template>
                     </el-table-column>
                     <el-table-column label="分配记录" prop="postilCount" align="center" width="90">
                       <template slot-scope="scope">
                         <span style="color:#ff5b5b;cursor: pointer;"
                         @click="addOrUpdateHandle(scope.row.Id)" v-if="scope.row.profit>=10000">记录({{ scope.row.postilCount?scope.row.postilCount:0 }})</span>
                         </template>
                      </el-table-column>
					<el-table-column label="操作" fixed="right" width="140">
						<template slot-scope="scope">
							<el-button type="text" @click="toDetailHandle(scope.row.Id,true)"  v-has="'btn_detail'">
								详细
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
			</div>
		</div>
        <Form v-if="formVisible" ref="Form" @refreshDatalist="initData" />
        <Detail v-show="offerVisible" ref="Detail" @refresh="refresh" />
	</div>
  </template> 
  <script>
    import request from '@/utils/request'
    import Form from './Form'
    import Detail from './Detail'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {Form,Detail},
        data() {
            return {
                showAll: false,
                query: {
					fullName:undefined,
					signingTime:undefined,
                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                offerVisible:false,
				proNameOptions:[],
            }
        },
        computed: {},
        created() {
			this.initData();
	    	this.getproNameOptions();
        },
        methods: {
		   getproNameOptions()
		   {
			  previewDataInterface('195045591036724485').then(res => {
				  this.proNameOptions = res.data
			  })
		   },
          tableRowClassName(
                {
                    row,
                    rowIndex
                }){
                if (row.profit >=10000&&row.lastTrackState==0) {
                    return 'warning-row';
                } else if (row.profit >=10000&&row.lastTrackState==1) {
                    return 'success-row';
                }
                return '';
            },
            initData() {
                this.listLoading = true;
                let _query = {
                    ...this.listQuery,
                    ...this.query
                };
                let query = {}
                for (let key in _query) {
                    if (Array.isArray(_query[key])) {
                        query[key] = _query[key].join()
                    } else {
                        query[key] = _query[key]
                    }
                }
                request({
                    url: `/api/SubDev/ZyOaProfit`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
             // 新增 / 修改
            addOrUpdateHandle(id) {
                 this.formVisible = true
                 this.$nextTick(() => {
                 this.$refs.Form.init(id)
                })
             },
            toDetailHandle(id,isDetail) {
                 this.offerVisible = true
                 this.$nextTick(() => {
                 this.$refs.Detail.init(id,isDetail)
                })
            },
            search() {
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.offerVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
        }
    }
</script>

<style>
.el-table .success-row {
    color: rgb(8, 117, 50) !important;
    background: rgba(250, 244, 244, 0.986)!important;
}
.el-table .warning-row {
    color: rgb(189, 29, 8) !important;
    background: rgba(238, 236, 236, 0.986)!important;
}
</style>

